<?php

namespace backend\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\helpers\Html;
use yii\helpers\Json;

/**
 * This is the model class for table "{{%ticket}}".
 *
 * @property int $id
 * @property string $title
 * @property int $code
 * @property int $rs
 * @property string|null $detail
 * @property string|null $created_at
 * @property string|null $updated_at
 *
 * @property TicketPatch[] $ticketPatches
 */
class Ticket extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%ticket}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['title'], 'required'],
            [['code', 'rs'], 'integer'],
            [['detail'], 'string'],
            [['created_at', 'updated_at'], 'safe'],
            [['title'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'Title',
            'code' => 'Code',
            'ticketLink' => 'Ticket',
            'rs' => 'Rs',
            'rsLink' => 'Rs',
            'detail' => 'Detail',
            'created_at' => 'Create Time',
            'updated_at' => 'Update Time',
        ];
    }

    /**
     * Gets query for [[TicketPatches]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getTicketPatches()
    {
        return $this->hasMany(TicketPatch::class, ['ticket_id' => 'id']);
    }

//    /**
//     * @return string
//     */
//    public function getTicketLink(): string
//    {
//        $url = Constant::TICKET_URI.'?'.http_build_query(['iid' => $this->code]);
//        return Html::a($this->code, $url, ['target' => '_blank']);
//    }
//
//    public function setTicketLink(...$arr)
//    {
//        halt($arr);
//        $this->code = $arr[0];
//    }

//    /**
//     * @return string
//     */
//    public function getRsLink(): string
//    {
//        $url = Constant::RS_URI.$this->rs;
//        return Html::a($this->code, $url, ['target' => '_blank']);
//    }
}
